package com.htsc.mrp.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author donghe@htsc.com
 * @ClassName: PagingResult
 * @Description: 分页结果
 * @CreateOn 2018/07/26 上午 10:52
 */
public class PagingResult<T> {

    // 当前页
    private int currentPage;

    //总页数
    private int totalPage;

    // 总共记录条数
    private int totalSize;

    //每页显示数量
    private int pageSize;

    // 结果集
    private List<T> dataList = new ArrayList<T>();


    /**
     * @Fields params : 查询条件
     */
    private Map<String, Object> params;

    /**
     * @return currentPage
     */
    public int getCurrentPage() {
        return currentPage;
    }

    /**
     * @param currentPage 要设置的 currentPage
     */
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    /**
     * @return totalSize
     */
    public int getTotalSize() {
        return totalSize;
    }

    /**
     * @param totalSize 要设置的 totalSize
     */
    public void setTotalSize(int totalSize) {
        this.totalSize = totalSize;
    }

    /**
     * Getter method for property &lt;tt&gt;dataList&lt;/tt&gt;.
     *
     * @return property value of dataList
     */
    public List<T> getDataList() {
        return dataList;
    }

    /**
     * Setter method for property &lt;tt&gt;dataList&lt;/tt&gt;.
     *
     * @param dataList value to be assigned to property dataList
     */
    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    /**
     * @return totalPage
     */
    public int getTotalPage() {
        if (this.totalPage > 0) {
            return this.totalPage;
        }
        this.totalPage = this.totalSize / this.pageSize;
        if ((this.totalSize % this.pageSize) > 0) {
            this.totalPage += 1;
        }
        return totalPage;
    }

    /**
     * @param totalPage 要设置的 totalPage
     */
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    /**
     * @return pageSize
     */
    public int getPageSize() {
        return pageSize;
    }

    /**
     * @param pageSize 要设置的 pageSize
     */
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }


    public int getPrevPage() {
        int p = this.currentPage - 1;
        if (p > 0) {
            return p;
        }
        return this.currentPage;
    }


    public int getNextPage() {
        int p = this.currentPage + 1;
        if (p > this.getTotalPage()) {
            return this.currentPage;
        }
        return p;
    }


    public boolean hasPrevPage() {
        return getPrevPage() < this.currentPage;
    }


    public boolean hasNextPage() {
        return getNextPage() > this.currentPage;
    }

    /**
     * get page no
     **/
    public long getFirstPage() {
        if ((currentPage - 1) > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    public long getLastPage() {
        if ((currentPage + 1) <= getTotalPage()) {
            return (getTotalPage());
        } else {
            return 0;
        }
    }


    public int getResultSize() {
        return this.dataList.size();
    }

    /**
     * @return params
     */
    public Map<String, Object> getParams() {
        return params;
    }

    /**
     * @param params 要设置的 params
     */
    public void setParams(Map<String, Object> params) {
        this.params = params;
    }




}
